# coding:utf8
"""
author:shadu@foxmail.com
"""
from redisdb import RedisDB

HISTORY_PROXY_EXPIRE_SECODNS = int(3600 * 24 * 1.5)


class ProxyQueue(object):
    redis_conn = RedisDB()
    proxy_queue_name = 'proxies_collected'

    @staticmethod
    def put(proxy):
        ProxyQueue.redis_conn.redis_conn_collected.lpush(ProxyQueue.proxy_queue_name, proxy)

    @staticmethod
    def qsize():
        return ProxyQueue.redis_conn.redis_conn_collected.llen(ProxyQueue.proxy_queue_name)

    @staticmethod
    def clear():
        ProxyQueue.redis_conn.redis_conn_collected.flushall()


class ProxyList(object):
    redis_conn = RedisDB()

    @staticmethod
    def put(proxy):
        ProxyList.redis_conn.redis_conn_to_veify.lpush('proxy_to_verify', proxy)
        if not ProxyList.redis_conn.redis_conn_history.exists(proxy):
            ProxyList.redis_conn.redis_conn_history.set(proxy, '1')
            ProxyList.redis_conn.redis_conn_history.expire(proxy, HISTORY_PROXY_EXPIRE_SECODNS)


if __name__ == '__main__':
    ProxyQueue.put('1.1.1.1:80')
    ProxyQueue.put('1.1.1.1:90')
    print ProxyQueue.qsize()
    ProxyQueue.clear()
